import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/res/lf_double_ext.dart';

import '../../../config/lf_config.dart';
import '../../../entity/entities/chat_new_message_entity.dart';
import '../../../res/lf_color.dart';
import '../../../res/lf_fonts.dart';
import '../../../res/lf_text_style.dart';
import '../../../res/strings/lf_strings.dart';
import '../../../service/lf_auth_service.dart';
import '../../../utils/lf_dialog_utils.dart';
import '../../lf_browser/lf_browser_logic.dart';

class LfMessageUnSupport extends StatelessWidget {
  final ChatNewMessageEntity data;
  const LfMessageUnSupport({
    Key? key,
    required this.data,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    LfAuthService authService = Get.find();
    var isSender =
        data.sender?.profile?.userId == authService.currentAccount!.userId;
    Widget text = RichText(
      text: TextSpan(
          text: "[${strUnsupportedMessage.tr} ",
          style: lfTextStyle(
              sp: 15.sp,
              fontFamily: fontRegular,
              color: isSender ? colorFEFEFE : colorFEFEFE),
          children: [
            TextSpan(
                text: webUrl,
                recognizer: TapGestureRecognizer()
                  ..onTap = () {
                    toBrowserPage(
                        title: appName,
                        url: webUrl);
                  },
                style: lfTextStyle(
                    sp: 18.sp,
                    fontFamily: fontMedium,
                    decoration: TextDecoration.underline,
                    color: isSender ? colorFEFEFE : colorFEFEFE)),
            TextSpan(
                text: "]",
                style: lfTextStyle(
                    sp: 18.sp,
                    fontFamily: fontRegular,
                    color: isSender ? colorFEFEFE :  colorFEFEFE))
          ]),
    );
    if (appIsDebug) {
      text = InkWell(
        child: text,
        onLongPress: () {
          if (appIsDebug) {
            showSnackBar(data.toJson().toString());
          }
        },
      );
    }
    if (isSender) {
      return Row(
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Flexible(
              child: Container(
            padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 10.w),
            decoration: BoxDecoration(
              color: color514F62,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10.r),
                  bottomRight: Radius.circular(10.r),
                  bottomLeft: Radius.circular(10.r)),
            ),
            constraints:
                BoxConstraints(maxWidth: ScreenUtil().screenWidth - 70.w),
            child: text,
          )),
          10.w.sbw
        ],
      );
    } else {
      return Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          10.w.sbw,
          // CustomCacheImage(
          //   imageUrl: data.sender?.profile?.avatarUrl,
          //   isCircle: true,
          //   width: 40.r,
          //   height: 40.r,
          // ),
          // 5.w.sbw,
          Flexible(
              child: Container(
            padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 10.w),
            decoration: BoxDecoration(
              color: color8F8F8F,
              borderRadius: BorderRadius.only(
                  topRight: Radius.circular(10.r),
                  bottomRight: Radius.circular(10.r),
                  bottomLeft: Radius.circular(10.r)),
            ),
            constraints:
                BoxConstraints(maxWidth: ScreenUtil().screenWidth - 70.w),
            child: text,
          )),
          10.w.sbw
        ],
      );
    }
  }
}
